package cn.lf.controller;


import cn.lf.dto.api.order.UserOrderDetailRepDTO;
import cn.lf.dto.api.order.UserOrderInfoGetRepDTO;
import cn.lf.dto.api.order.UserOrderInfoGetReqDTO;
import cn.lf.dto.order.*;
import cn.lf.service.ApiOrderService;
import cn.lf.utils.ResponseModel;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/order")
@Api(tags = "订单信息相关接口")
public class ApiOrderController {

    @Autowired
    ApiOrderService orderService;

    @PostMapping("/createUserOrderInfo")
    @ApiOperation("创建用户订单信息")
    public ResponseModel createUserOrderInfo(@RequestBody UserOrderInfoGenReqDTO userOrderInfoGenReqDTO){

        orderService.createUserOrderInfo(userOrderInfoGenReqDTO);

        return ResponseModel.buildSuccessResult();
    }

    @GetMapping("/getUserOrderInfo")
    @ApiOperation("获取用户的订单列表信息")
    public ResponseModel<IPage<UserOrderInfoGetRepDTO>> getUserOrderInfo(UserOrderInfoGetReqDTO userOrderInfoGetReqDTO){

        IPage<UserOrderInfoGetRepDTO> result = orderService.getUserOrderInfo(userOrderInfoGetReqDTO);

        return ResponseModel.buildSuccessResult(result);
    }

    @GetMapping("/getUserOrderDetailById")
    @ApiOperation("获取用户的订单详细信息（包括商品）")
    public ResponseModel<UserOrderDetailRepDTO> getUserOrderDetailById(String orderId){

        UserOrderDetailRepDTO result = orderService.getUserOrderDetailById(orderId);

        return ResponseModel.buildSuccessResult(result);
    }

    @GetMapping("/paymentForOrder")
    @ApiOperation("为订单付款")
    public ResponseModel paymentForOrder(PfoReqDTO pfoReqDTO){

        orderService.paymentForOrder(pfoReqDTO);

        return ResponseModel.buildSuccessResult();
    }

    @GetMapping("/cancelOrder")
    @ApiOperation("取消订单")
    public ResponseModel cancelOrder(CancelOrderReqDTO cancelOrderReqDTO){

        orderService.cancelOrder(cancelOrderReqDTO);

        return ResponseModel.buildSuccessResult();
    }

    @GetMapping("/getUserOrderDetailById")
    @ApiOperation("申请退款")
    public ResponseModel applyOrderRefund(AorReqDTO aorReqDTO){

        orderService.applyOrderRefund(aorReqDTO);

        return ResponseModel.buildSuccessResult();
    }

}
